//
//  BTianConfigSchema.swift
//  btvideo
//
//  Created by Jason on 2021/9/15.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import Foundation
import NSObject_Rx
import RxSwift
import RxCocoa


//MARK: - Tian Config
class ST_TianAssetConfigComponent:NSObject{
    
    lazy var big_image_suffix = "imageView2/0/w/1242/h/1242/interlace/1"
    
    lazy var mid_image_suffix = "imageView2/0/w/750/h/750/interlace/1"
    
    lazy var small_image_suffix = "imageView2/0/w/300/h/300/interlace/1"
    
    lazy var upload_compress_value:Float = 0.5
    
    override init() {
        
        super.init()
        
        /// 这个配置 影响很小，时机改为 IM 服务  sync  完成后，再加个随机时间 seconds ( 50...200) 再请求配置
        NotificationCenter.default.rx.notification(.i_msync_o_k).delay(RxTimeInterval.seconds(Int.random(in: 50...200)), scheduler: ConcurrentDispatchQueueScheduler.init(queue: .global())).subscribe(onNext: { _ in
            
            self.pull_config()
            
        }).disposed(by: rx.disposeBag)
        
    }
    
}

extension ST_TianAssetConfigComponent{
    
    private func pull_config(){
        
        /// 获取广告图 时机，暂时 绑定到这里吧
        ST_AdvertManger.shared.fetch_advert_list()
        
        JVrequest(PH.niuCloudConfigApi) { (json) in
            
            let data = json["data"]["ios"]
            
            self.big_image_suffix = data["big_img"].stringValue
            
            self.mid_image_suffix = data["medium_img"].stringValue
            
            self.small_image_suffix = data["small_img"].stringValue
            
            self.upload_compress_value = data["rate"].floatValue
            
        } failure: { (code, err) in
            
        }
        
    }
    
}
